﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace GTA
{
    public partial class FrmTasks : BaseForm
    {
        #region Local Objects
        private List<BusinessEntity.Task> tasksFound;
        #endregion

        #region Start Form
        public FrmTasks()
        {
            InitializeComponent();
            RestoreListColumnState(lstScenarios);
        }
        private void FrmCenarios_Load(object sender, EventArgs e)
        {
            StartForm();

        }
        private void StartForm()
        {
            LoadCategories();
            LoadStates();
            SetStartDatesFilter();
            ConfiureTaskColorStatusPanels();
            if (Program.LoggedUser.UserProfile == BusinessEntity.UserManagement.Profiler.User)
                cmdComments.Enabled = false;
            RestoreSearchFilter();
        }
        #endregion

        #region Events
        private void cmdSearch_Click(object sender, EventArgs e)
        {
            SearchScenarios();
        }
        private void cmdCleanFilter_Click(object sender, EventArgs e)
        {
            CleanFilter();
        }
        private void cmdDetails_Click(object sender, EventArgs e)
        {
            ShowSelectedTaskDetails();
        }
        private void cmdPrint_Click(object sender, EventArgs e)
        {
            PrintSearch();
        }
        private void cmdExportXLS_Click(object sender, EventArgs e)
        {
            ExportSearchXLS();
        }
        private void detalhesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowSelectedTaskDetails();
        }
        private void lstScenarios_DoubleClick(object sender, EventArgs e)
        {
            ShowSelectedTaskDetails();
        }
        private void lstScenarios_ColumnClick(object sender, ColumnClickEventArgs e)
        {
            SortList(lstScenarios, GetColumnTypeLstScenarios(e.Column), ref columnOrder, ref sortOrder, e.Column);
        }
        private void imprimirConsultaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PrintSearch();
        }
        private void exportarConsultaParaXLSToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ExportSearchXLS();
        }
        private void comentariosToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EditTaskComments();
        }
        private void historicoDaTaskToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EditTaskHistory();
        }
        private void cmdComments_Click(object sender, EventArgs e)
        {
            EditTaskComments();
        }
        private void cmdTaskHistory_Click(object sender, EventArgs e)
        {
            EditTaskHistory();
        }
        private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
        {
            comentariosToolStripMenuItem.Enabled = lstScenarios.SelectedItems.Count == 1 && Program.LoggedUser.UserProfile == BusinessEntity.UserManagement.Profiler.Master;
            historicoDaTaskToolStripMenuItem.Enabled = lstScenarios.SelectedItems.Count == 1;
        }
        private void lstScenarios_SelectedIndexChanged(object sender, EventArgs e)
        {
            cmdComments.Enabled = lstScenarios.SelectedItems.Count == 1 && Program.LoggedUser.UserProfile == BusinessEntity.UserManagement.Profiler.Master;
            cmdTaskHistory.Enabled = lstScenarios.SelectedItems.Count == 1;
        }
        private void lstScenarios_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e)
        {
            SaveListColumnState(lstScenarios);
        }
        #endregion

        #region Methods
        private void ConfiureTaskColorStatusPanels()
        {
            pnlStatusAlertaEntrega.BackColor = Color.FromArgb(
                                 Program.SystemConfiguration.General.StatusColor.StatusAlertaEntregaBackColor.Red,
                                 Program.SystemConfiguration.General.StatusColor.StatusAlertaEntregaBackColor.Green,
                                 Program.SystemConfiguration.General.StatusColor.StatusAlertaEntregaBackColor.Blue);
            pnlStatusAlertaInicio.BackColor = Color.FromArgb(
                                 Program.SystemConfiguration.General.StatusColor.StatusAlertaInicioBackColor.Red,
                                 Program.SystemConfiguration.General.StatusColor.StatusAlertaInicioBackColor.Green,
                                 Program.SystemConfiguration.General.StatusColor.StatusAlertaInicioBackColor.Blue);
            pnlStatusAtrasoEntreag.BackColor = Color.FromArgb(
                                 Program.SystemConfiguration.General.StatusColor.StatusAtrasoEntregaBackColor.Red,
                                 Program.SystemConfiguration.General.StatusColor.StatusAtrasoEntregaBackColor.Green,
                                 Program.SystemConfiguration.General.StatusColor.StatusAtrasoEntregaBackColor.Blue);
            pnlStatusAtrasoInicio.BackColor = Color.FromArgb(
                                 Program.SystemConfiguration.General.StatusColor.StatusAtrasoInicioBackColor.Red,
                                 Program.SystemConfiguration.General.StatusColor.StatusAtrasoInicioBackColor.Green,
                                 Program.SystemConfiguration.General.StatusColor.StatusAtrasoInicioBackColor.Blue);
            pnlStatusCancelado.BackColor = Color.FromArgb(
                                 Program.SystemConfiguration.General.StatusColor.StatusCanceladoBackColor.Red,
                                 Program.SystemConfiguration.General.StatusColor.StatusCanceladoBackColor.Green,
                                 Program.SystemConfiguration.General.StatusColor.StatusCanceladoBackColor.Blue);
            pnlStatusConcluido.BackColor = Color.FromArgb(
                                 Program.SystemConfiguration.General.StatusColor.StatusFinalizadoBackColor.Red,
                                 Program.SystemConfiguration.General.StatusColor.StatusFinalizadoBackColor.Green,
                                 Program.SystemConfiguration.General.StatusColor.StatusFinalizadoBackColor.Blue);
        }
        private void SetStartDatesFilter()
        {
            txtFilterDateScheduleEndIni.Value = DateTime.Now.AddDays(-30);
            txtFilterDateScheduleEndEnd.Value = DateTime.Now.AddDays(30);
            txtFilterDateScheduleStartIni.Value = DateTime.Now.AddDays(-30);
            txtFilterDateScheduleStartEnd.Value = DateTime.Now.AddDays(30);
            txtFilterDateScheduleEndIni.Checked = false;
            txtFilterDateScheduleEndEnd.Checked = false;
            txtFilterDateScheduleStartIni.Checked = false;
            txtFilterDateScheduleStartEnd.Checked = false;
        }
        private void LoadStates()
        {
            try
            {
                BusinessLogic.GTA bl = new BusinessLogic.GTA();
                List<BusinessEntity.TaskDomain> states = bl.ListStates();
                if (states != null)
                    states.ForEach(item => lstStates.Items.Add(item.Description));

            }
            catch (Exception ex)
            {
                HandleException("Carregar a lista de status", ex);
            }
        }
        private void LoadCategories()
        {
            try
            {
                BusinessLogic.GTA bl = new BusinessLogic.GTA();
                List<BusinessEntity.TaskDomain> categories = bl.ListCategories();
                if (categories != null)
                    categories.ForEach(item => lstCategories.Items.Add(item.Description));
            }
            catch (Exception ex)
            {
                HandleException("Carregar a lista de categorias", ex);
            }
        }
        private void CleanResults()
        {
            try
            {
                lstScenarios.Items.Clear();
                tasksFound = null;
                lblQtdTasks.Text = lstScenarios.Items.Count.ToString();
                SaveFilter();
            }
            catch (Exception ex)
            {
                HandleException("Limpar os filtros da pesquisa", ex);
            }
        }
        private void SearchScenarios()
        {
            try
            {
                Cursor = Cursors.WaitCursor;
                BusinessLogic.GTA bl = new BusinessLogic.GTA();
                BusinessEntity.TaskFilter filter = GetSearchFilter();
                SaveFilter();
                List<BusinessEntity.Task> list = bl.ListArchitectureTasks(filter, Program.LoggedUser);
                tasksFound = list;
                lstScenarios.Items.Clear();
                if (list != null && list.Count > 0)
                {
                    foreach (BusinessEntity.Task item in list)
                    {
                        ListViewItem newItem = new ListViewItem(item.Project != null ? item.Project.Name : String.Empty);
                        newItem.SubItems.Add(item.Category != null ? item.Category.Description : String.Empty);
                        newItem.SubItems.Add(item.DesignedTo != null ? item.DesignedTo.Name : String.Empty);
                        newItem.SubItems.Add(item.Title);
                        newItem.SubItems.Add(item.State != null ? item.State.Description : String.Empty);
                        newItem.SubItems.Add(item.ID.ToString());
                        newItem.SubItems.Add(item.ScheduleEstimatedStart != DateTime.MinValue ? item.ScheduleEstimatedStart.ToString(DATE_FORMAT_FULL) : String.Empty);
                        newItem.SubItems.Add(item.ScheduleEstimatedEnd != DateTime.MinValue ? item.ScheduleEstimatedEnd.ToString(DATE_FORMAT_FULL) : String.Empty);
                        newItem.SubItems.Add(item.ScheduleRealizedStart != DateTime.MinValue ? item.ScheduleRealizedStart.ToString(DATE_FORMAT_FULL) : String.Empty);
                        newItem.SubItems.Add(item.ScheduleRealizedEnd != DateTime.MinValue ? item.ScheduleRealizedEnd.ToString(DATE_FORMAT_FULL) : String.Empty);
                        newItem.SubItems.Add(item.ScheduleEstimatedHours.ToString());
                        newItem.SubItems.Add(item.Reason);
                        if (item.UserHistory != null && item.UserHistory.Count > 0)
                            newItem.ImageIndex = 0;

                        if (item.State != null)
                        {
                            //Status Finalizado
                            if (item.State.Description.ToLowerInvariant().CompareTo("finalizado") == 0)
                            {
                                SetListViewItemBackColor(newItem, Program.SystemConfiguration.General.StatusColor.StatusFinalizadoBackColor);
                                SetListViewItemForeColor(newItem, Program.SystemConfiguration.General.StatusColor.StatusFinalizadoForeColor);
                            }
                            //Status Cancelado - Status == "Cancelado"
                            else if (item.State.Description.ToLowerInvariant().CompareTo("cancelado") == 0)
                            {
                                SetListViewItemBackColor(newItem, Program.SystemConfiguration.General.StatusColor.StatusCanceladoBackColor);
                                SetListViewItemForeColor(newItem, Program.SystemConfiguration.General.StatusColor.StatusCanceladoForeColor);
                            }
                            //Atraso na Entrega - Status != "Finalizado" e hoje > "Termino Previsto"
                            else if (item.State.Description.ToLowerInvariant().CompareTo("finalizado") != 0 &&
                                DateTime.Now.Date.CompareTo(item.ScheduleEstimatedEnd.Date) > 0)
                            {
                                SetListViewItemBackColor(newItem, Program.SystemConfiguration.General.StatusColor.StatusAtrasoEntregaBackColor);
                                SetListViewItemForeColor(newItem, Program.SystemConfiguration.General.StatusColor.StatusAtrasoEntregaForeColor);
                            }
                            //Atraso no Início - "Início" não informado && "Início Previsto" <= hoje && Status != "Finalizado".
                            else if (item.State.Description.ToLowerInvariant().CompareTo("finalizado") != 0 &&
                                item.ScheduleRealizedStart == DateTime.MinValue &&
                                item.ScheduleEstimatedStart.Date.CompareTo(DateTime.Now.Date) <= 0)
                            {
                                SetListViewItemBackColor(newItem, Program.SystemConfiguration.General.StatusColor.StatusAtrasoInicioBackColor);
                                SetListViewItemForeColor(newItem, Program.SystemConfiguration.General.StatusColor.StatusAtrasoInicioForeColor);
                            }
                            //Alerta de Entrega - hoje <= ("Termino Previsto" - 4)
                            else if (item.State.Description.ToLowerInvariant().CompareTo("finalizado") != 0 &&
                                DateTime.Now.Date.CompareTo(item.ScheduleEstimatedEnd.AddDays(-2).Date) >= 0 &&
                                DateTime.Now.Date.CompareTo(item.ScheduleEstimatedEnd.Date) <= 0)
                            {
                                SetListViewItemBackColor(newItem, Program.SystemConfiguration.General.StatusColor.StatusAlertaEntregaBackColor);
                                SetListViewItemForeColor(newItem, Program.SystemConfiguration.General.StatusColor.StatusAlertaEntregaForeColor);
                            }
                            //Alerta de Início - "Início" não informado && hoje >= ("Início Previsto" - 4)
                            else if (item.State.Description.ToLowerInvariant().CompareTo("finalizado") != 0 &&
                                item.ScheduleRealizedStart == DateTime.MinValue &&
                                DateTime.Now.Date.CompareTo(item.ScheduleEstimatedStart.AddDays(-2).Date) >= 0 &&
                                DateTime.Now.Date.CompareTo(item.ScheduleEstimatedStart.Date) <= 0)
                            {
                                SetListViewItemBackColor(newItem, Program.SystemConfiguration.General.StatusColor.StatusAlertaInicioBackColor);
                                SetListViewItemForeColor(newItem, Program.SystemConfiguration.General.StatusColor.StatusAlertaInicioForeColor);
                            }
                        }
                        lstScenarios.Items.Add(newItem);
                    }
                }
                else
                    MessageBox.Show("Nenhum retorno!", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);

                lblQtdTasks.Text = lstScenarios.Items.Count.ToString();
            }
            catch (Exception ex)
            {
                HandleException("Pesquisa cenários de Arquitetura", ex);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
        private static void SetListViewItemBackColor(ListViewItem newItem, BusinessEntity.Configuration.TaskStatusColor.Color statusColor)
        {
            newItem.BackColor = Color.FromArgb(statusColor.Red, statusColor.Green, statusColor.Blue);
        }
        private static void SetListViewItemForeColor(ListViewItem newItem, BusinessEntity.Configuration.TaskStatusColor.Color statusColor)
        {
            newItem.ForeColor = Color.FromArgb(statusColor.Red, statusColor.Green, statusColor.Blue);
        }
        private BusinessEntity.TaskFilter GetSearchFilter()
        {
            BusinessEntity.TaskFilter filter = new GTA.BusinessEntity.TaskFilter();
            if (!String.IsNullOrEmpty(txtTaskID.Text))
                filter.ID = Convert.ToInt32(txtTaskID.Text);
            if (txtFilterDateScheduleEndIni.Checked)
                filter.ScheduleEstimatedEndFrom = txtFilterDateScheduleEndIni.Value;
            if (txtFilterDateScheduleEndEnd.Checked)
                filter.ScheduleEstimatedEndTo = txtFilterDateScheduleEndEnd.Value;
            if (txtFilterDateScheduleStartIni.Checked)
                filter.ScheduleEstimatedStartFrom = txtFilterDateScheduleStartIni.Value;
            if (txtFilterDateScheduleStartEnd.Checked)
                filter.ScheduleEstimatedStartTo = txtFilterDateScheduleStartEnd.Value;
            filter.Project = ucSearchFilter1.GetSelectedProjects();
            filter.DesignedTo = ucSearchFilter1.GetSelectedResponsibles();
            if (lstCategories.CheckedItems.Count > 0)
                filter.Category = GetSelectedCategories();
            if (lstStates.CheckedItems.Count > 0)
                filter.State = GetSelectedStates();
            return filter;
        }
        private List<BusinessEntity.TaskDomain> GetSelectedStates()
        {
            List<BusinessEntity.TaskDomain> states = null;
            if (lstStates.CheckedItems.Count > 0)
            {
                states = new List<GTA.BusinessEntity.TaskDomain>();
                foreach (ListViewItem item in lstStates.CheckedItems)
                    states.Add(new GTA.BusinessEntity.TaskDomain(0, item.Text));
            }
            return states;
        }
        private List<BusinessEntity.TaskDomain> GetSelectedCategories()
        {
            List<BusinessEntity.TaskDomain> categories = null;
            if (lstCategories.CheckedItems.Count > 0)
            {
                categories = new List<GTA.BusinessEntity.TaskDomain>();
                foreach (ListViewItem item in lstCategories.CheckedItems)
                    categories.Add(new GTA.BusinessEntity.TaskDomain(0, item.Text));
            }
            return categories;
        }
        private OrdenacaoListView.Tipo GetColumnTypeLstScenarios(Int32 column)
        {
            OrdenacaoListView.Tipo tipoColuna;
            switch (column)
            {
                case 0:
                    tipoColuna = OrdenacaoListView.Tipo.Alfabetica;
                    break;
                case 1:
                    tipoColuna = OrdenacaoListView.Tipo.Alfabetica;
                    break;
                case 2:
                    tipoColuna = OrdenacaoListView.Tipo.Alfabetica;
                    break;
                case 3:
                    tipoColuna = OrdenacaoListView.Tipo.Alfabetica;
                    break;
                case 4:
                    tipoColuna = OrdenacaoListView.Tipo.Alfabetica;
                    break;
                case 5:
                    tipoColuna = OrdenacaoListView.Tipo.Numerica;
                    break;
                case 6:
                    tipoColuna = OrdenacaoListView.Tipo.Data;
                    break;
                case 7:
                    tipoColuna = OrdenacaoListView.Tipo.Data;
                    break;
                case 8:
                    tipoColuna = OrdenacaoListView.Tipo.Data;
                    break;
                case 9:
                    tipoColuna = OrdenacaoListView.Tipo.Data;
                    break;
                case 10:
                    tipoColuna = OrdenacaoListView.Tipo.Numerica;
                    break;
                case 11:
                    tipoColuna = OrdenacaoListView.Tipo.Alfabetica;
                    break;
                default:
                    tipoColuna = OrdenacaoListView.Tipo.Alfabetica;
                    break;
            }
            return tipoColuna;
        }
        private void CleanFilter()
        {
            try
            {
                txtTaskID.Text = String.Empty;
                SetStartDatesFilter();
                ClearListCheckedItems(lstCategories);
                ClearListCheckedItems(lstStates);
                ucSearchFilter1.CleanFilter();
                txtFilterDateScheduleStartIni.Focus();
            }
            catch (Exception ex)
            {
                HandleException("Clean search filter", ex);
            }
        }
        private void ClearListCheckedItems(ListView list)
        {
            foreach (ListViewItem item in list.CheckedItems)
                item.Checked = false;
        }
        private void ShowSelectedTaskDetails()
        {
            try
            {
                if (lstScenarios.SelectedItems.Count > 0)
                {
                    if (lstScenarios.SelectedItems.Count == 1)
                    {
                        Int32 idx = tasksFound.FindIndex(itemTask => itemTask.ID.CompareTo(Convert.ToInt32(lstScenarios.SelectedItems[0].SubItems[5].Text)) == 0);
                        FrmTaskDetails wd = new FrmTaskDetails(tasksFound, idx);
                        wd.ShowInTaskbar = false;
                        wd.ShowDialog(this);
                    }
                    else
                        MessageBox.Show("Selecione apenas uma task para visualizar os detalhes!", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                    MessageBox.Show("Selecione uma task para visualizar os detalhes!", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (Exception ex)
            {
                HandleException("Abrir detalhes da task", ex);
            }
        }
        private void PrintSearch()
        {
            try
            {
                if (tasksFound != null && tasksFound.Count > 0)
                {
                    BusinessLogic.GTA bl = new BusinessLogic.GTA();
                    String htmlContent = bl.GetArchitectureTasksHTMLFormat(tasksFound);
                    FrmPrint wd = new FrmPrint(htmlContent);
                    wd.Show(this);
                }
            }
            catch (Exception ex)
            {
                HandleException("Imprimir resultado da pesquisa", ex);
            }
        }
        private void ExportSearchXLS()
        {
            try
            {
                if (tasksFound != null && tasksFound.Count > 0)
                {
                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        String pathXlsFile = saveFileDialog.FileName;
                        BusinessLogic.GTA bl = new BusinessLogic.GTA();
                        bl.ExportXlsArchitectureTasks(tasksFound, pathXlsFile);
                        if (MessageBox.Show("Arquivo salvo com sucesso.\r\n\r\nDeseja abrir o arquivo!?", "Confirmação", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                            System.Diagnostics.Process.Start(pathXlsFile);
                    }
                }
            }
            catch (Exception ex)
            {
                HandleException("Exportar resultado da pesquisa para XLS", ex);
            }
        }
        private BusinessEntity.Task GetSelectedTask()
        {
            BusinessEntity.Task task = null;
            if (lstScenarios.SelectedItems.Count == 1)
                task = tasksFound.Find(it => it.ID.CompareTo(Convert.ToInt32(lstScenarios.SelectedItems[0].SubItems[5].Text)) == 0);
            return task;
        }
        private void EditTaskComments()
        {
            try
            {
                if (lstScenarios.SelectedItems.Count == 1)
                {
                    FrmTaskComments wd = new FrmTaskComments(GetSelectedTask());
                    wd.ShowInTaskbar = false;
                    wd.ShowDialog(this);
                }
                else
                    MessageBox.Show("Selecione uma task para visualizar os comentários!", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (Exception ex)
            {
                HandleException("Abrir os comentários da task", ex);
            }
        }
        private void EditTaskHistory()
        {
            try
            {
                if (lstScenarios.SelectedItems.Count == 1)
                {
                    FrmTaskHistory wd = new FrmTaskHistory(GetSelectedTask());
                    wd.ShowInTaskbar = false;
                    wd.ShowDialog(this);
                }
                else
                    MessageBox.Show("Selecione uma task para visualizar os históricos!", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (Exception ex)
            {
                HandleException("Abrir os históricos da task", ex);
            }
        }
        private void SaveFilter()
        {
            try
            {
                BusinessEntity.TaskFilter filter = GetSearchFilter();
                Program.SystemConfiguration.FilterSearchFrmTasks = new GTA.BusinessEntity.Configuration.SearchFilter(filter);
                Program.SaveSystemConfiguration();
            }
            catch (Exception ex)
            {
                HandleException("Salvar o filtro da pesquisa.", ex);
            }
        }
        private void RestoreSearchFilter()
        {
            try
            {
                if (Program.SystemConfiguration.FilterSearchFrmTasks != null)
                {
                    ucSearchFilter1.RestoreSearchFilterProjects(Program.SystemConfiguration.FilterSearchFrmTasks.Project);
                    ucSearchFilter1.RestoreSearchFilterResponsibles(Program.SystemConfiguration.FilterSearchFrmTasks.DesignedTo);

                    if (Program.SystemConfiguration.FilterSearchFrmTasks.Category != null &&
                        Program.SystemConfiguration.FilterSearchFrmTasks.Category.Count > 0)
                    {
                        foreach (ListViewItem lstItem in lstCategories.Items)
                        {
                            if (Program.SystemConfiguration.FilterSearchFrmTasks.Category.Exists(it => it.Description.CompareTo(lstItem.SubItems[0].Text) == 0))
                                lstItem.Checked = true;
                        }
                    }
                    if (Program.SystemConfiguration.FilterSearchFrmTasks.State != null &&
                        Program.SystemConfiguration.FilterSearchFrmTasks.State.Count > 0)
                    {
                        foreach (ListViewItem lstItem in lstStates.Items)
                        {
                            if (Program.SystemConfiguration.FilterSearchFrmTasks.State.Exists(it => it.Description.CompareTo(lstItem.SubItems[0].Text) == 0))
                                lstItem.Checked = true;
                        }
                    }
                    if (Program.SystemConfiguration.FilterSearchFrmTasks.ScheduleEstimatedEndFrom != DateTime.MinValue)
                    {
                        txtFilterDateScheduleEndIni.Checked = true;
                        txtFilterDateScheduleEndIni.Value = Program.SystemConfiguration.FilterSearchFrmTasks.ScheduleEstimatedEndFrom;
                    }
                    if (Program.SystemConfiguration.FilterSearchFrmTasks.ScheduleEstimatedEndTo != DateTime.MinValue)
                    {
                        txtFilterDateScheduleEndEnd.Checked = true;
                        txtFilterDateScheduleEndEnd.Value = Program.SystemConfiguration.FilterSearchFrmTasks.ScheduleEstimatedEndTo;
                    }
                    if (Program.SystemConfiguration.FilterSearchFrmTasks.ScheduleEstimatedStartFrom != DateTime.MinValue)
                    {
                        txtFilterDateScheduleStartIni.Checked = true;
                        txtFilterDateScheduleStartIni.Value = Program.SystemConfiguration.FilterSearchFrmTasks.ScheduleEstimatedStartFrom;
                    }
                    if (Program.SystemConfiguration.FilterSearchFrmTasks.ScheduleEstimatedStartTo != DateTime.MinValue)
                    {
                        txtFilterDateScheduleStartEnd.Checked = true;
                        txtFilterDateScheduleStartEnd.Value = Program.SystemConfiguration.FilterSearchFrmTasks.ScheduleEstimatedStartTo;
                    }
                    if (Program.SystemConfiguration.FilterSearchFrmTasks.ID != 0 && Program.SystemConfiguration.FilterSearchFrmTasks.ID != Int32.MinValue)
                        txtTaskID.Text = Program.SystemConfiguration.FilterSearchFrmTasks.ID.ToString();
                }
            }
            catch (Exception ex)
            {
                HandleException("Restaurar os últimos filtros utilizados.", ex);
            }
        }
        #endregion
    }
}

